package com.cyys.common.utils.list;

import com.cyys.common.model.BaseBean;
import com.google.common.base.Function;
import com.google.common.collect.Maps;

import java.util.List;
import java.util.Map;

public class ListUtil {

	public static Map<String, ?> listToMap(List<? extends BaseBean> list) {
		Map<String, ?> map = Maps.uniqueIndex(list, new Function<BaseBean, String>() {
			public String apply(BaseBean from) {
				return from.getId();
			}
		});
		return map;
	}

	public static String[] listToStringArray(List<String> list) {
		if(list != null || list.size() > 0){
			String strings ="";
			return list.toArray(new String[list.size()]);
		}
		return null;
	}

	public static String listToStrings(List<String> list) {
		if(list != null || list.size() > 0){
			String strings ="";
			String[] str2=list.toArray(new String[list.size()]);
			for (String string : str2) {
				strings += string + ",";
			}
			strings = strings.substring(0,strings.lastIndexOf(","));
			return strings;
		}
		return "";
	}


	public static void main(String[] args) {
//		ParamBasic p1 = new ParamBasic();
//		p1.setId(1);
//		p1.setName("111");
//
//		ParamBasic p2 = new ParamBasic();
//		p2.setId(2);
//		p2.setName("222");
//
//		List<ParamBasic> pl = new ArrayList<>();
//		pl.add(p1);
//		pl.add(p2);

//		Map<Integer, ParamBasic> map = (Map<Integer, ParamBasic>) ListUtil.listToMap(pl);
//		for (Integer in : map.keySet()) {
//			// map.keySet()返回的是所有key的值
//			ParamBasic str = map.get(in);// 得到每个key多对用value的值
//			System.out.println(str.getName());
//		}

	}
}
